package demo09;

/**
 * 第八题: 通过代码, 完成如下需求:		//本题和集合无关, 就是想考察下大家关于: "面向过程"和"面向对象"编程的理解.
 * 1. 已知字符串String str = "heimaheimawoaiheima,buguanheimahaishibaima,zhaodaogongzuojiushihaoma";
 * 2. 写代码实现查找上述字符串中”heima”字符串出现的次数,并将结果打印到控制台上.
 */
public class demo09 {
    public static void main(String[] args) {
        String str = "heimaheimawoaiheima,buguanheimahaishibaima,zhaodaogongzuojiushihaoma";
        String str2 = "heima";
        int count = 0;
        for (int i = 0; i < str.length() - str2.length(); i++) {
            if (str2.equals(str.substring(i, i + str2.length())))
                count++;
        }
        System.out.println(count);
    }
}
